00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _pf_components_h_
00019 #define _pf_components_h_
00020
00021 #include "boost/smart_ptr/shared_ptr.hpp"
00022 #include "gridpack/utilities/complex.hpp"
00023 #include "gridpack/component/base_component.hpp"
00024 #include "gridpack/component/data_collection.hpp"
00025 #include "gridpack/applications/components/y_matrix/ymatrix_components.hpp"
00026
00027 namespace gridpack {
00028 namespace powerflow {
00029
00030 enum PFMode{YBus, Jacobian, RHS, S_Cal, State};
00031
00032 class PFBus
00033 : public gridpack::ymatrix::YMBus
00034 {
00035 public:
00036
00037
00038
00039 PFBus(void);
00040
00041
00042
00043
00044 ~PFBus(void);
00045
00046
00047
00048
00049
00050
00051
00052
00053 bool matrixDiagSize(int *isize, int *jsize) const;
00054
00055
00056
00057
00058
00059
00060
00061
00062 bool matrixDiagValues(ComplexType *values);
00063 bool matrixDiagValues(RealType *values);
00064
00065
00066
00067
00068
00069
00070
00071 bool vectorSize(int *isize) const;
00072
00073
00074
00075
00076
00077
00078
00079 bool vectorValues(ComplexType *values);
00080 bool vectorValues(RealType *values);
00081
00082
00083
00084
00085
00086
00087 void setValues(gridpack::ComplexType *values);
00088 void setValues(gridpack::RealType *values);
00089
00090
00091
00092
00093
00094
00095 int getXCBufSize(void);
00096
00097
00098
00099
00100 void setXCBuf(void *buf);
00101
00102
00103
00104
00105
00106 void setYBus(void);
00107
00108
00109
00110
00111
00112 gridpack::ComplexType getYBus(void);
00113
00114
00115
00116
00117
00118
00119
00120
00121 void load(const boost::shared_ptr<gridpack::component::DataCollection> &data);
00122
00123
00124
00125
00126
00127
00128 void setMode(int mode);
00129
00130
00131
00132
00133 void resetVoltage(void);
00134
00135
00136
00137
00138
00139
00140 void setVoltageLimits(double vmin, double vmax);
00141
00142
00143
00144
00145
00146 bool checkVoltageViolation(void);
00147
00148
00149
00150
00151
00152 double getVoltage(void);
00153
00154
00155
00156
00157
00158 ComplexType getComplexVoltage(void);
00159
00160
00161
00162
00163
00164 double getPhase(void);
00165
00166
00167
00168
00169
00170
00171 bool getGenStatus(std::string gen_id);
00172
00173
00174
00175
00176
00177 std::vector<std::string> getGenerators();
00178
00179
00180
00181
00182
00183 std::vector<std::string> getLoads();
00184
00185
00186
00187
00188
00189
00190 bool isPV(void);
00191
00192
00193
00194
00195 void setVoltage(void);
00196
00197
00198
00199
00200 void setPhase(void);
00201
00202
00203
00204
00205
00206
00207 void setGenStatus(std::string gen_id, bool status);
00208
00209
00210
00211
00212
00213 void setIsPV(int status);
00214
00215
00216
00217
00218 void resetIsPV();
00219
00220
00221
00222
00223
00224 void setSBus(void);
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242 bool serialWrite(char *string, const int bufsize, const char *signal = NULL);
00243
00244
00245
00246
00247
00248 bool chkQlim(void);
00249
00250
00251
00252
00253
00254 void clearQlim();
00255
00256
00257
00258
00259
00260
00261
00262 void saveData(boost::shared_ptr<gridpack::component::DataCollection>
00263 data);
00264
00265
00266
00267
00268
00269
00270
00271
00272 void setParam(std::string name, int busID, std::string genID, double value);
00273 void setParam(int busID, std::string genID, double value);
00274
00275
00276
00277
00278
00279
00280
00281
00282 void getParam(std::string &name, double *value, int idx);
00283 void getParam(std::string &name, int *value, int idx);
00284
00285
00286
00287
00288
00289
00290
00291 int getElementIndex(std::string &name, std::string &tag);
00292
00293
00294
00295
00296
00297 void setIgnore(bool flag);
00298
00299
00300
00301
00302
00303 bool getIgnore();
00304
00305
00306
00307
00308
00309 int getArea();
00310
00311
00312
00313
00314
00315 int getZone();
00316
00317
00318
00319
00320
00321
00322
00323 int diagonalJacobianValues(double *rvals);
00324
00325
00326
00327
00328
00329
00330
00331 int rhsValues(double *rvals);
00332
00333
00334
00335
00336 void pushIsPV();
00337
00338
00339
00340
00341
00342 std::vector<double> getGeneratorParticipation();
00343
00344
00345
00346
00347
00348
00349
00350 void setGeneratorRealPower(std::string tag, double value,
00351 gridpack::component::DataCollection *data);
00352
00353
00354
00355
00356
00357
00358 void scaleGeneratorRealPower(std::string tag, double value);
00359
00360
00361
00362
00363
00364
00365
00366 void setLoadRealPower(std::string tag, double value,
00367 gridpack::component::DataCollection *data);
00368
00369
00370
00371
00372
00373
00374 void scaleLoadPower(std::string tag, double value);
00375
00376
00377
00378
00379 void resetPower();
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389 void getGeneratorMargins(std::vector<std::string> &tag,
00390 std::vector<double> ¤t, std::vector<double> &pmin,
00391 std::vector<double> &pmax, std::vector<int> &status);
00392
00393
00394
00395
00396
00397
00398
00399
00400 void getLoadPower(std::vector<std::string> &tag, std::vector<double> &pl,
00401 std::vector<double> &ql, std::vector<int> &status);
00402
00403
00404
00405
00406
00407 void setSource(bool flag);
00408
00409
00410
00411
00412
00413 void setSink(bool flag);
00414
00415
00416
00417
00418
00419 void setScale(double scale);
00420
00421 private:
00422 double p_shunt_gs;
00423 double p_shunt_bs;
00424 bool p_shunt;
00425 bool p_load;
00426 int p_mode;
00427 bool p_ignore;
00428
00429
00430
00431 double p_v, p_a;
00432 double p_theta;
00433 double p_ybusr, p_ybusi;
00434 double p_P0, p_Q0;
00435 double p_angle;
00436 double p_voltage;
00437
00438 std::vector<double> p_pg, p_qg, p_pFac;
00439 std::vector<double> p_savePg;
00440 std::vector<int> p_gstatus;
00441 std::vector<int> p_gstatus_save;
00442 std::vector<double> p_qmax,p_qmin;
00443 std::vector<double> p_qmax_orig, p_qmin_orig, p_pFac_orig;
00444 std::vector<double> p_vs;
00445 std::vector<std::string> p_gid;
00446 std::vector<double> p_pt;
00447 std::vector<double> p_pb;
00448 std::vector<double> p_pl, p_ql,p_ip,p_iq,p_yp,p_yq;
00449 std::vector<double> p_savePl;
00450 std::vector<double> p_saveQl;
00451 std::vector<int> p_lstatus;
00452 std::vector<std::string> p_lid;
00453 double p_sbase;
00454 double p_Pinj, p_Qinj;
00455 double p_vmin, p_vmax;
00456 bool p_isPV, p_saveisPV, p_save2isPV;
00457 bool *p_PV_ptr;
00458 int p_ngen;
00459 int p_nload;
00460 int p_type;
00461 int p_area;
00462 int p_zone;
00463 bool p_source;
00464 bool p_sink;
00465 double p_rtpr_scale;
00466 bool p_original_isolated;
00467
00468
00469
00470
00471 double* p_vMag_ptr;
00472 double* p_vAng_ptr;
00473
00474
00475
00476
00477 gridpack::component::DataCollection *p_data;
00478
00479 private:
00480
00481
00482 friend class boost::serialization::access;
00483
00484 template<class Archive>
00485 void serialize(Archive & ar, const unsigned int version)
00486 {
00487 ar & boost::serialization::base_object<gridpack::ymatrix::YMBus>(*this)
00488 & p_shunt_gs
00489 & p_shunt_bs
00490 & p_shunt
00491 & p_load
00492 & p_mode
00493 & p_ignore
00494 & p_v & p_a & p_theta
00495 & p_ybusr & p_ybusi
00496 & p_P0 & p_Q0
00497 & p_angle & p_voltage
00498 & p_pg & p_qg & p_pFac & p_qmin & p_qmax
00499 & p_qmin_orig & p_qmax_orig & p_pFac_orig
00500 & p_gstatus
00501 & p_vs & p_gid
00502 & p_pt & p_pb
00503 & p_pl & p_ql & p_ip & p_iq & p_yp & p_yq
00504 & p_savePl & p_saveQl
00505 & p_lstatus & p_lid
00506 & p_sbase
00507 & p_Pinj & p_Qinj
00508 & p_vmin & p_vmax
00509 & p_isPV
00510 & p_saveisPV
00511 & p_ngen & p_type & p_nload
00512 & p_area & p_zone
00513 & p_source & p_sink
00514 & p_rtpr_scale;
00515 }
00516
00517 };
00518
00519 class PFBranch
00520 : public gridpack::ymatrix::YMBranch {
00521 public:
00522
00523
00524
00525 PFBranch(void);
00526
00527
00528
00529
00530 ~PFBranch(void);
00531
00532
00533
00534
00535
00536
00537
00538 bool matrixForwardSize(int *isize, int *jsize) const;
00539 bool matrixReverseSize(int *isize, int *jsize) const;
00540
00541
00542
00543
00544
00545
00546
00547 bool matrixForwardValues(ComplexType *values);
00548 bool matrixReverseValues(ComplexType *values);
00549 bool matrixForwardValues(RealType *values);
00550 bool matrixReverseValues(RealType *values);
00551
00552
00553
00554
00555
00556 void setYBus(void);
00557
00558
00559
00560
00561
00562 gridpack::ComplexType getYBus(void);
00563
00564
00565
00566
00567
00568
00569
00570
00571 void load(const boost::shared_ptr<gridpack::component::DataCollection> &data);
00572
00573
00574
00575
00576
00577
00578
00579
00580 void getJacobian(PFBus *bus, double *values);
00581
00582
00583
00584
00585
00586
00587 void getPQ(PFBus *bus, double *p, double *q);
00588
00589
00590
00591
00592
00593
00594 void setMode(int mode);
00595
00596
00597
00598
00599
00600
00601 gridpack::ComplexType getComplexPower(std::string tag);
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611 bool serialWrite(char *string, const int bufsize, const char *signal = NULL);
00612
00613
00614
00615
00616
00617
00618 bool getBranchStatus(std::string tag);
00619
00620
00621
00622
00623
00624
00625 void setBranchStatus(std::string tag, bool status);
00626
00627
00628
00629
00630
00631
00632 double getBranchRatingA(std::string tag);
00633
00634
00635
00636
00637
00638
00639 double getBranchRatingB(std::string tag);
00640
00641
00642
00643
00644
00645
00646 double getBranchRatingC(std::string tag);
00647
00648
00649
00650
00651
00652 std::vector<std::string> getLineIDs();
00653
00654
00655
00656
00657
00658
00659 void setIgnore(std::string tag, bool flag);
00660
00661
00662
00663
00664
00665
00666 bool getIgnore(std::string tag);
00667
00668
00669
00670
00671
00672
00673
00674 int forwardJacobianValues(double *rvals);
00675 int reverseJacobianValues(double *rvals);
00676
00677 private:
00678 std::vector<bool> p_ignore;
00679 std::vector<double> p_reactance;
00680 std::vector<double> p_resistance;
00681 std::vector<double> p_tap_ratio;
00682 std::vector<double> p_phase_shift;
00683 std::vector<double> p_charging;
00684 std::vector<double> p_shunt_admt_g1;
00685 std::vector<double> p_shunt_admt_b1;
00686 std::vector<double> p_shunt_admt_g2;
00687 std::vector<double> p_shunt_admt_b2;
00688 std::vector<bool> p_xform, p_shunt;
00689 std::vector<double> p_rateA;
00690 std::vector<double> p_rateB;
00691 std::vector<double> p_rateC;
00692 std::vector<bool> p_branch_status;
00693 std::vector<std::string> p_ckt;
00694 int p_mode;
00695 double p_ybusr_frwd, p_ybusi_frwd;
00696 double p_ybusr_rvrs, p_ybusi_rvrs;
00697 double p_theta;
00698 double p_sbase;
00699 int p_elems;
00700 bool p_active;
00701
00702 private:
00703
00704
00705 friend class boost::serialization::access;
00706
00707 template<class Archive>
00708 void serialize(Archive & ar, const unsigned int version)
00709 {
00710 ar & boost::serialization::base_object<gridpack::ymatrix::YMBranch>(*this)
00711 & p_ignore
00712 & p_reactance
00713 & p_resistance
00714 & p_tap_ratio
00715 & p_phase_shift
00716 & p_charging
00717 & p_shunt_admt_g1
00718 & p_shunt_admt_b1
00719 & p_shunt_admt_g2
00720 & p_shunt_admt_b2
00721 & p_xform & p_shunt
00722 & p_rateA
00723 & p_branch_status
00724 & p_ckt
00725 & p_mode
00726 & p_ybusr_frwd & p_ybusi_frwd
00727 & p_ybusr_rvrs & p_ybusi_rvrs
00728 & p_theta
00729 & p_sbase
00730 & p_elems
00731 & p_active;
00732 }
00733
00734 };
00735
00736
00737 }
00738 }
00739
00740 BOOST_CLASS_EXPORT_KEY(gridpack::powerflow::PFBus)
00741 BOOST_CLASS_EXPORT_KEY(gridpack::powerflow::PFBranch)
00742
00743
00744 #endif